<?php
namespace Modules\AuthAdmin\Services;
use Tymon\JWTAuth\Facades\JWTAuth;
class AuthAdminService  
{
	 public function __construct()
    {
        \Config::set('auth.defaults.guard', 'auth_admin');
		\Config::set('jwt.ttl', 60);
    }
	
	/**
     * @name 设置token
     */
	public function set_token($data){
		if (! $token = JWTAuth::attempt($data)){  
            return [];
        }
		return $this->respond_with_token($token);
	}
	/**	 
	 * @name  我的信息	 
	 */
	public function my(){
		return JWTAuth::parseToken()->touser();
	}
	/**	 
	 * @name  退出登录
	 */
    public function logout()
    {
        return JWTAuth::parseToken()->invalidate();
    }
	/**	 
	 * @name  刷新	 
	 */
    public function refresh()
    {
        return $this->respond_with_token(JWTAuth::parseToken()->refresh());
    }	
	/**
     * @name 组合token数据
     */
	protected function respond_with_token($token)
    {
        return [
				'token' => $token,
				'token_type' => 'bearer',
				'expires_in' => JWTAuth::factory()->getTTL() * 60
			];
    }
}
